﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Services.Protocols;
using System.Windows.Forms;

namespace Client
{
    public partial class Form1 : Form
    {
        private static CookieContainer cookieBox = new CookieContainer();

        private localhost.TestServices testService;

        public Form1()
        {
            InitializeComponent();
            InitService();
        }

        private void InitService() 
        {
            testService = new localhost.TestServices();
            testService.CookieContainer = cookieBox;
            testService.Credentials = CredentialCache.DefaultCredentials;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            if (string.IsNullOrEmpty(name)) return;

            try
            {
                testService.AccessTokenSoapHeaderValue =new localhost.AccessTokenSoapHeader() { AccessToken = "ywt" };
                testService.Login(name, "111");
                name = testService.CurrentUser();
                MessageBox.Show(name);
            }
            catch (SoapException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string name = testService.CurrentUser();
            MessageBox.Show(name);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (testService == null) return;
            testService.LogOut();
        }
    }
}
